home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group92c.txt
/
000032_icon-group-sender _Thu Oct 22 06:18:10 1992.msg
< prev
next >
Wrap
Internet Message Format
|
1993-01-04
|
3KB
Received: by cheltenham.cs.arizona.edu; Thu, 22 Oct 1992 06:00:08 MST
Date: Thu, 22 Oct 92 06:18:10 -0400
From: isidev!nowlin@uunet.uu.net
Message-Id: <9210221018.AA22763@relay1.UU.NET>
To: uunet!cs.arizona.edu!icon-group@uunet.UU.NET
Subject: Re: skipping comments
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
> From: uunet!arizona!CU.NIH.GOV!UBY
> Date: Tue, 13 Oct 1992 11:31:31 EDT
> Subject: How to skip comments?
>
> I have been trying to modify the concord.icn program from the Icon program
> library to produce cross-reference tables for SAS programs, but I am
> stumped about how to skip over comments. Comments in the SAS language are
> of the form /* ..... */. I have not been able to figure out how to skip
> the comments and still persuade A*B to parse as A and B. The relevent code
> is appended. Any suggestions would be greatly appreciated.
>
> Thanks,
>
> Jim Blakley UBY@NIHCU.BITNET
>
> An Icon novice in over his depth
I took the procedure you posted and extrapolated a main() procedure to test
it with. Including a main() is a good idea when posting code. Sometimes
no main() can obscure the meaning of code fragments. I assumed lineno and
keywords were supposed to be global and just threw in some C keywords for
testing.
Then I added a new procedure called stripcom() that does what you want.
It's been over eight years since I did any SAS but C uses the same
commenting convention so I had plenty of code to test this on. See if this
is what you had in mind.
This could probably be done in a more iconic fashion but that would just
make the code harder to follow and you said you're a novice. If you have
questions let me know. I tried mailing directly but had no luck.
Jerry Nowlin
uunet!isidev!nowlin
isidev!nowlin@uunet.uu.net
--------------------------------> cut here <-------------------------------
##### ORIGINAL CODE
procedure item()
local i, word, line
static char1, sasvar, sas
initial {
char1 := '&%_' ++ &letters
sasvar := char1 ++ &digits
}
while line := read() do {
lineno +:= 1
write(right(lineno, 6), " ", line)
line := map(stripcom(line)) # fold to lowercase
i := 1
line ? {
while tab(upto(sasvar)) do {
word := tab(many(sasvar))
if member(keywords, word) then next # skip reserved words
if word ? any(char1) then suspend word # skip numbers
}
}
}
end
##### NEW CODE
procedure stripcom(old)
local new
static incom, begcom, endcom
initial { incom := &null ; begcom := "/*" ; endcom := "*/" }
new := ""
old ? while not pos(0) do {
\incom & ((tab(find(endcom)) & incom := &null) | tab(0))
while new ||:= tab(find(begcom)) do {
move(2)
(tab(find(endcom)) & move(2) & incom := &null) |
(tab(0) & incom := 1)
}
new ||:= tab(0)
}
return new
end
global lineno, keywords
procedure main()
lineno := 0
keywords:= set(["break","case","continue","do","else",
"for","if","return","switch","while"])
every write(item())
end